package com.tsk.example.result;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.Arrays;

/**
 * @author: 黄嘉振
 * @create: 2023/4/19 10:57
 * @description:
 **/
@Component
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException {
        System.out.println("====================================");
        String[] beanNames = factory.getBeanNamesForAnnotation(RestControllerAdvice.class);
        for (String beanName : beanNames) {
            System.out.println("beanName: " + beanName);
            RestControllerAdvice restControllerAdvice = factory.findAnnotationOnBean(beanName, RestControllerAdvice.class);
            String[] basePackages = restControllerAdvice.basePackages();
            System.out.println("RestControllerAdvice " + beanName + " 包名：" + Arrays.toString(basePackages));
        }
    }
}
